home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11360 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  84 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.sprintlink.net!news1!news
  3. From: tjones@walknet.com
  4. Subject: Need help!
  5. X-Nntp-Posting-Host: ind-006-236-227.iquest.net
  6. Message-ID: <Do858A.Btr@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Internet, Inc.
  9. X-Newsreader: Forte Free Agent 1.0.82
  10. Date: Thu, 14 Mar 1996 00:05:03 GMT
  11.  
  12. /* 
  13.    I have just started using C++ and have the problem below.  Any
  14.    advice would be appreciated.
  15.  
  16.    Can data structures be passed to classes?  In this overly simple
  17.    program below, I can fill a data structure in the desc function
  18.    of the reg class, but I can not decrement
  19.    to the beginning of the structure, so that I can print it out
  20.    within the class function.
  21.  
  22.    Please pardon the mix of C and C++ code.
  23.  
  24.    Please e-mail any suggestions to TJONES@WALKERNET.COM
  25. */
  26.  
  27.  
  28. #include <dos.h>
  29. #include <stdlib.h>
  30. #include <math.h>
  31. #include <dir.h>
  32. #include <stdio.h>
  33. #include <string.h>
  34.  
  35.  
  36.  
  37. struct data { char name[50];}; 
  38.  
  39. class reg {
  40.       public:
  41.       void init(void);
  42.       void desc(struct data *dptr);
  43.       } reg1;
  44.  
  45. void reg::init(void)
  46. {
  47.  
  48. }
  49. void reg::desc(struct data *dptr)
  50. {      int y=0,x=0;
  51.       
  52.     for(y=0;y<25;y++)
  53.     {for(x=0;x<y;x++) strcat(dptr->name,"A");
  54.      printf("%s\n",dptr->name);
  55.      dptr++; 
  56.     }
  57.  
  58.     /* Here is the problem area*/
  59.  
  60.     for(y=0;y<25;y++) dptr--;
  61.        
  62.     for(y=0;y<25;y++)
  63.     printf("\n%4d %s",y,dptr->name);
  64.  
  65. }
  66.  
  67. int main(void)
  68. {
  69.  struct data rrdata[25];   struct data *rptr;
  70.  memset(rrdata,0,sizeof(struct data)*25);
  71.  
  72.  reg1.init();
  73.  
  74.  rptr=&rrdata[0];
  75.  reg1.desc(rptr);
  76.  
  77.  for(int x=0;x<25;x++)
  78.  printf("\n%4d %s",x,rrdata[x].name);
  79.  
  80.  return 0;     
  81. }
  82.  
  83.  
  84.